{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 作业三： \n",
    "写一个可以将MNIST图片向任意方向（上，下，左，右）移动一个像素功能。然后对训练集中的每张图片，创建四个位移后的副本，每个方向一个，添加到训练集。最后，在这个扩展过的训练集上训练模型，衡量其在测试集上的精度，来优化精度，这种人工扩展训练集的技术成为数据增广或训练集扩展"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\users\\tians\\appdata\\local\\programs\\python\\python37\\lib\\importlib\\_bootstrap.py:219: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility. Expected 216, got 192\n",
      "  return f(*args, **kwds)\n",
      "c:\\users\\tians\\appdata\\local\\programs\\python\\python37\\lib\\importlib\\_bootstrap.py:219: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility. Expected 192 from C header, got 216 from PyObject\n",
      "  return f(*args, **kwds)\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.datasets import fetch_mldata\n",
    "from sklearn.metrics import confusion_matrix,precision_score,recall_score\n",
    "from sklearn.model_selection import cross_val_score,GridSearchCV\n",
    "from sklearn.neighbors import KNeighborsClassifier\n",
    "from scipy.ndimage.interpolation import shift\n",
    "\n",
    "def show_img1(X,i):\n",
    "    some_digit = X[i]\n",
    "    some_digit_image = some_digit.reshape(28,28)\n",
    "    plt.imshow(some_digit_image,cmap = plt.cm.binary)\n",
    "    plt.show()\n",
    "\n",
    "def show_img2(X,i):\n",
    "    some_digit = X[i]\n",
    "    some_digit_image = some_digit.reshape(28,28)\n",
    "    plt.imshow(some_digit_image,cmap = plt.cm.binary,interpolation='nearest')\n",
    "    plt.axis('off')\n",
    "    plt.show()\n",
    "    \n",
    "def shift_img(img,dx,dy):\n",
    "    img = img.reshape(28,28)\n",
    "    shifted_image = shift(img,[dx,dy])\n",
    "    return shifted_image.reshape(-1)\n",
    "\n",
    "def show_shifted_img(X,i,dx,dy):\n",
    "    some_digit = X[i]\n",
    "    some_digit_shifted = shift_img(some_digit,dx,dy).reshape(28,28)\n",
    "    plt.imshow(some_digit_shifted,cmap=plt.cm.binary,interpolation='nearest')\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "mnist = fetch_mldata('MNIST original',data_home = './')\n",
    "X,y = mnist['data'], mnist['target']\n",
    "X_train,X_test,y_train,y_test = X[:60000], X[60000:], y[:60000], y[60000:]\n",
    "shuffle_index = np.random.permutation(60000)\n",
    "X_train, y_train = X_train[shuffle_index], y_train[shuffle_index]\n",
    "y_train_9 = (y_train == 9)\n",
    "y_test_9 = (y_test == 9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2., 1., 7., 0., 8., 8., 7., 1., 9., 9.])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_train[0:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOcAAADnCAYAAADl9EEgAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8GearUAAAFsElEQVR4nO3dv2sUWxjHYVcCaSMEm7QBm5Q2ghCwMZVoZyGIrZ0IEskfEaz8CcHOQpAoWNgJYqOgRbATFCGNCAFFw4Ks9cXdd647u9nvkOcp78uZPSx8HMi5M9sbDAZHgDxHZ70BYDhxQihxQihxQihxQqi5hrk/5cL09Yb9R3dOCCVOCCVOCCVOCCVOCCVOCCV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D0S3fnhFDihFDihFDihFDihFDihFCOUobY29sr502vr5z1Y1+VNkcp01btbdr7Onv2bDl//vz5ND/eUQp0iTghlDghlDghlDghlDghlDghlFdjDvH+/ftyfv/+/QPaCQdld3d31lv4izsnhBInhBInhBInhBInhBInhBInhHLOOYamZyKb5rM0y70tLy+X8+/fv4+cNb2Wc2VlpZzv7OyU89+/f5fzWXDnhFDihFDihFDihFDihFDihFDihFDOOcfQ9h2qbdYfP368nK+urpbzY8eOlfOLFy/+857+r5MnT5bz6n3BS0tLk95OPHdOCCVOCCVOCCVOCCVOCCVOCOUnAIfo9/vl/O7du+X848eP5fzt27cjZxsbG+XaU6dOlfOFhYVyTiQ/AQhdIk4IJU4IJU4IJU4IJU4IJU4I5ZwTZs85J3SJOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCGUOCHUXMO8dyC7AP7izgmhxAmhxAmhxAmhxAmhxAmh/gD6ROf5zISLqAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "show_img2(X_train,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 784)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_digit = X_train[0:1]\n",
    "test_digit.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 0, 0, 0, 0],\n",
       "       [0, 0, 1, 0, 0],\n",
       "       [0, 1, 0, 1, 0],\n",
       "       [0, 0, 1, 0, 0],\n",
       "       [0, 0, 0, 0, 0]])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_arr = np.array([0,0,0,0,0,\n",
    "                     0,0,1,0,0,\n",
    "                     0,1,0,1,0,\n",
    "                     0,0,1,0,0,\n",
    "                     0,0,0,0,0,]).reshape(5,5)\n",
    "test_arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 0, 0, 0, 0],\n",
       "       [0, 0, 0, 0, 0],\n",
       "       [0, 0, 1, 0, 0],\n",
       "       [0, 1, 0, 1, 0],\n",
       "       [0, 0, 1, 0, 0]])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "teat_arr_down = shift(test_arr,[1,0])\n",
    "teat_arr_down"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 0, 1, 0, 0],\n",
       "       [0, 1, 0, 1, 0],\n",
       "       [0, 0, 1, 0, 0],\n",
       "       [0, 0, 0, 0, 0],\n",
       "       [0, 0, 0, 0, 0]])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "teat_arr_up = shift(test_arr,[-1,0])\n",
    "teat_arr_up"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 0, 0, 0, 0],\n",
       "       [0, 0, 0, 1, 0],\n",
       "       [0, 0, 1, 0, 1],\n",
       "       [0, 0, 0, 1, 0],\n",
       "       [0, 0, 0, 0, 0]])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "teat_arr_right = shift(test_arr,[0,1])\n",
    "teat_arr_right"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 0, 0, 0, 0],\n",
       "       [0, 1, 0, 0, 0],\n",
       "       [1, 0, 1, 0, 0],\n",
       "       [0, 1, 0, 0, 0],\n",
       "       [0, 0, 0, 0, 0]])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "teat_arr_left = shift(test_arr,[0,-1])\n",
    "teat_arr_left"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 使用一个简单的图形矩阵演示shift方法是如何操作的，观察矩阵和图像的变化关系"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAA2EAAADACAYAAACNpGvpAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8GearUAAAapUlEQVR4nO3de7QkZX3u8edhBhSFcJLMNpqBOEQxwy0qs0UULxyOHlBRj5dEEYnkRNEcdaGRYAwxGc1KjmZpYtaSeILCgRMw5EKOMSbGhZGRoISwB/DCjCgxowzXTZDAyD388sf7bqamp3d377273663+/tZq9fs6qpd9auqp2v3r6q6xxEhAAAAAEAZe4y7AAAAAACYJjRhAAAAAFAQTRgAAAAAFEQTBgAAAAAF0YQBAAAAQEE0YQAAAABQEE3YENneZvv0Jf5O2H7tkOvYaPubw5wn2sv2upyj2SX8zjH5d9YMsY5Ntj8+rPkts4YlvZ5GsR2wu2nM6HL+HnSZB/lsuSnN9pKXZfto21+3/aDtTSMqbapNYxb7afsxlCasg+21ts+2vT0fLG6y/Unb+w/w68+S9EdLXOSTJP3N0isFVuSrStn7t1ILtH2K7R0jXszQX0+F6sbuJ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plain": [
       "<Figure size 1080x216 with 5 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(15,3))\n",
    "plt.subplot(1,5,1)\n",
    "plt.title('Original',fontsize=14)\n",
    "plt.imshow(test_arr,cmap=plt.cm.binary)\n",
    "plt.subplot(1,5,2)\n",
    "plt.title('move lpixel to right',fontsize=14)\n",
    "plt.imshow(shift(test_arr,[0,1]),cmap=plt.cm.binary)\n",
    "plt.subplot(1,5,3)\n",
    "plt.title('move lpixel to below',fontsize=14)\n",
    "plt.imshow(shift(test_arr,[1,0]),cmap=plt.cm.binary)\n",
    "plt.subplot(1,5,4)\n",
    "plt.title('move lpixel to left',fontsize=14)\n",
    "plt.imshow(shift(test_arr,[0,-1]),cmap=plt.cm.binary)\n",
    "plt.subplot(1,5,5)\n",
    "plt.title('move lpixel to above',fontsize=14)\n",
    "plt.imshow(shift(test_arr,[-1,0]),cmap=plt.cm.binary)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(784,)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_img = X_train[0]\n",
    "test_img.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(784,)"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_img_right = shift_img(X_train[0],0,1)\n",
    "test_img_right.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.ndarray"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(test_img)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.ndarray"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(test_img_right)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,  28, 167, 221, 172,  72,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,  85, 221, 254, 254,\n",
       "       254, 201,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  69, 249, 232,\n",
       "       109,  17, 186, 201,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  94,\n",
       "       252, 102,   0,   0,  15, 225, 110,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "        23, 242, 112,   0,   0,   0,  54, 250, 123,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   5, 145, 142,   0,   0,   0,   0,  62, 254, 111,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,  36, 227,   0,   0,   0,   0,   0, 131, 254,  35,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,  33, 181,   0,   0,   0,   0,   0, 185,\n",
       "       250,  32,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "        27, 243, 198,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0, 101, 254,  84,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0, 216, 254,  26,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,  74, 251, 170,   1,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0, 218, 254,  23,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   2, 144, 255, 172,   2,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   4,  82, 254, 241,  19,\n",
       "         0,  10,  44, 117, 192,  32,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  30, 254, 254,\n",
       "       183, 124, 174, 219, 254, 237, 170,  11,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  22, 106, 223,\n",
       "       254, 254, 254, 254, 238, 179, 139,  42,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   5,  85, 193, 243,\n",
       "       254, 252, 203, 148, 149,  64,  25,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  62, 254,\n",
       "       254, 252, 236, 117,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "        62, 254, 238, 143,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0], dtype=uint8)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_img"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  16,  75,\n",
       "       153, 232, 233,  74,   2,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   6,  64,  64, 169,\n",
       "       232, 252, 252, 252, 253, 252,  91,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 110, 252,\n",
       "       252, 253, 252, 252, 252, 252, 253, 252, 170,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   8,  78,\n",
       "       245, 253, 253, 254, 253, 253, 253, 253, 254, 253, 188,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "       157, 252, 252, 252, 252, 253, 252, 157,  63, 221, 253, 252, 187,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0, 200, 252, 252, 252, 252, 214,  47,  11,  32, 232, 253,\n",
       "       252, 231,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0, 122, 252, 252, 236, 145,   0,   0,   0,  91,\n",
       "       252, 253, 252, 231,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   7, 121, 147,  66,   0,   0,   0,\n",
       "         9, 204, 252, 253, 252, 187,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0, 145, 253, 253, 255, 253, 127,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0, 100, 247, 252, 252, 253, 252, 126,   0,   0,   0,\n",
       "        29,  78,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,  84, 221, 252, 252, 252, 253, 252, 233, 153,\n",
       "       232, 233, 239, 251, 179,   4,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,  16, 152, 253, 252, 252, 252, 252, 253, 252,\n",
       "       252, 252, 252, 253, 252, 252, 252, 182,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,  64, 252, 253, 252, 252, 252, 252,\n",
       "       253, 252, 252, 252, 252, 253, 252, 252, 252, 208,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,  64, 253, 254, 253, 253,\n",
       "       253, 253, 255, 253, 253, 253, 218, 230, 211, 167, 211, 211,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  64, 252, 253,\n",
       "       252, 252, 231, 168, 151,  63,  63,  63,  11,  27,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   6,\n",
       "       109, 144, 196,  73,  16,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0], dtype=uint8)"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_img_right"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 把刚才的shift方法用在真正的mnist数据上，确认效果正常\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAA2gAAADACAYAAABxsUAjAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8GearUAAAgAElEQVR4nO3df7xVd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ACwQANAAAAAALR9AGamc00s5+Z2eNm1tns5dfKzG43s2fMrDdVe42Z3Wdmj/nfY1vZxqLM7PVm9gMz22FmPzGzT/l6lOvTKGQ2HGS2GDIbDjJbDJkNB5ktjtyGo91y29QBmpmdIGm5pHdJeqOkq8zsjc1sQx2sljSzpNYp6X7n3FmS7ve3Y/CipEXOuXMlXSzpE/75iHV96o7MBofMVkBmg0NmKyCzwSGzBZDb4LRVbpv9CdpFkh53zv3COXdE0hpJVza5DTVxzj0o6bmS8pWSuv3f3ZLe09RGDZFzbq9z7hH/935JOyRNVKTr0yBkNiBkthAyGxAyWwiZDQiZLYzcBqTdctvsAdpESbtSt5/ytdid6pzbKyUBkTShxe2pmplNkvQWSQ+pDdanjshsoMhsWWQ2UGS2LDIbKDI7KHIbqHbIbbMHaJZT4zr/LWZmJ0m6W9KnnXPPt7o9gSGzASKzgyKzASKzgyKzASKzFZHbALVLbps9QHtK0utTt18naU+T29AIT5vZ6ZLkfz/T4vYUZmavUBLkO51z3/TlaNenAchsYMhsRWQ2MGS2IjIbGDJbCLkNTDvlttkDtC2SzjKzM8xspKS5ktY3uQ2NsF7SfP/3fEnrWtiWwszMJN0maYdz7supu6JcnwYhswEhs4WQ2YCQ2ULIbEDIbGHkNiBtl1vnXFN/JL1b0s8lPSFpcbOXX4f2f0PSXkkvKHn35MOSXqvkyjCP+d+vaXU7C67LdCUfxz8qaZv/eXes69PA7URmA/khs4W3E5kN5IfMFt5OZDaQHzJb1bYit4H8tFtuza8UAAAAAKDFmv5F1QAAAACAfAzQAAAAACAQDNAAAAAAIBAM0AAAAAAgEAzQAAAAACAQDNAAAAAAIBAM0AAAAAAgEP8fhQ+xaxHOldoAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 1080x216 with 5 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(15,3))\n",
    "plt.subplot(1,5,1)\n",
    "plt.title('Original',fontsize=14)\n",
    "plt.imshow(test_digit.reshape(28,28),cmap=plt.cm.binary)\n",
    "plt.subplot(1,5,2)\n",
    "plt.title('move lpixel to right',fontsize=14)\n",
    "plt.imshow(shift_img(test_digit,5,0).reshape(28,28),cmap=plt.cm.binary)\n",
    "plt.subplot(1,5,3)\n",
    "plt.title('move lpixel to below',fontsize=14)\n",
    "plt.imshow(shift_img(test_digit,0,5).reshape(28,28),cmap=plt.cm.binary)\n",
    "plt.subplot(1,5,4)\n",
    "plt.title('move lpixel to left',fontsize=14)\n",
    "plt.imshow(shift_img(test_digit,-5,0).reshape(28,28),cmap=plt.cm.binary)\n",
    "plt.subplot(1,5,5)\n",
    "plt.title('move lpixel to above',fontsize=14)\n",
    "plt.imshow(shift_img(test_digit,0,-5).reshape(28,28),cmap=plt.cm.binary)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 a\n",
      "2 b\n",
      "3 c\n",
      "4 d\n",
      "5 e\n"
     ]
    }
   ],
   "source": [
    "x = [1,2,3,4,5]\n",
    "y = ['a','b','c','d','e']\n",
    "\n",
    "for i,j in zip(x,y):\n",
    "    print(i,j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wall time: 37.5 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "y_train_shifted = []\n",
    "X_train_shifted = []\n",
    "\n",
    "for img,label in zip(X_train,y_train):\n",
    "    for dx,dy in [[1,0],[0,1],[-1,0],[0,-1]]:\n",
    "        X_train_shifted.append(shift_img(img,dx,dy))\n",
    "        y_train_shifted.append(label)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(240000, 784)"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_train_shifted = np.array(X_train_shifted)\n",
    "X_train_shifted.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(240000,)"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_train_shifted = np.array(y_train_shifted)\n",
    "y_train_shifted.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  28, 167, 221,\n",
       "       172,  72,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  85, 221,\n",
       "       254, 254, 254, 201,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  69,\n",
       "       249, 232, 109,  17, 186, 201,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,  94, 252, 102,   0,   0,  15, 225, 110,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,  23, 242, 112,   0,   0,   0,  54, 250, 123,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   5, 145, 142,   0,   0,   0,   0,  62, 254, 111,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,  36, 227,   0,   0,   0,   0,   0, 131,\n",
       "       254,  35,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,  33, 181,   0,   0,   0,   0,\n",
       "         0, 185, 250,  32,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,  27, 243, 198,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0, 101, 254,  84,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0, 216, 254,  26,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,  74, 251, 170,   1,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0, 218, 254,  23,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   2, 144, 255, 172,\n",
       "         2,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   4,  82, 254,\n",
       "       241,  19,   0,  10,  44, 117, 192,  32,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  30,\n",
       "       254, 254, 183, 124, 174, 219, 254, 237, 170,  11,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,  22,\n",
       "       106, 223, 254, 254, 254, 254, 238, 179, 139,  42,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   5,  85,\n",
       "       193, 243, 254, 252, 203, 148, 149,  64,  25,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "        62, 254, 254, 252, 236, 117,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,  62, 254, 238, 143,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,\n",
       "         0,   0,   0,   0], dtype=uint8)"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_train_shifted[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2., 2., 2., 2., 1., 1., 1., 1., 7., 7.])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_train_shifted[:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(240000,)"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_train_shifted_9 = (y_train_shifted==9)\n",
    "y_train_shifted_9.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wall time: 11min 36s\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski',\n",
       "           metric_params=None, n_jobs=1, n_neighbors=5, p=2,\n",
       "           weights='uniform')"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "knn_clf = KNeighborsClassifier()\n",
    "knn_clf.fit(X_train_shifted,y_train_shifted_9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 784)"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_img1 = X_train_shifted[0:1]\n",
    "test_img1.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([False])"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "knn_clf.predict(test_img1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wall time: 1d 19h 3min 12s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "train_score = cross_val_score(knn_clf,X_train_shifted,y_train_shifted_9,cv=5,scoring='accuracy')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9924625039049136"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_score.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[Parallel(n_jobs=4)]: Done   2 out of   5 | elapsed: 376.2min remaining: 564.4min\n",
      "[Parallel(n_jobs=4)]: Done   5 out of   5 | elapsed: 582.6min finished\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wall time: 9h 42min 46s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "from sklearn.model_selection import cross_val_predict\n",
    "y_train_pred = cross_val_predict(knn_clf,X_train_shifted,y_train_shifted_9,cv=5,verbose=3,n_jobs=4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([False, False, False, False, False, False, False, False, False,\n",
       "       False])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_train_pred[:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[215240,    964],\n",
       "       [   897,  22899]], dtype=int64)"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "confusion_matrix(y_train_shifted_9,y_train_pred)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "精度: 95.96 %\n",
      "召回率: 96.23 %\n"
     ]
    }
   ],
   "source": [
    "print('精度: {0:.2f} %'.format(100*precision_score(y_train_shifted_9,y_train_pred)))\n",
    "print('召回率: {0:.2f} %'.format(100*recall_score(y_train_shifted_9,y_train_pred)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wall time: 47min 49s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "y_test_pred = knn_clf.predict(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[8955,   36],\n",
       "       [  39,  970]], dtype=int64)"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "confusion_matrix(y_test_9,y_test_pred)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "精度: 96.42 %\n",
      "召回率: 96.13 %\n"
     ]
    }
   ],
   "source": [
    "print('精度: {0:.2f} %'.format(100*precision_score(y_test_9,y_test_pred)))\n",
    "print('召回率: {0:.2f} %'.format(100*recall_score(y_test_9,y_test_pred)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9925"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.metrics import accuracy_score\n",
    "accuracy_score(y_test_9,y_test_pred)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## <font color='red'>答案：比起没有被预处理的数据，旋转之后的数据集数量和样式都变多，最终出来的模型的精度也有提升，对比如下：</font>\n",
    "## <font color='red'>有预处理的数据精度（96.42%），没有预处理的数据精度（95.96%）</font>\n",
    "## <font color='red'>有预处理的数据模型召回率（96.13%），没有预处理的数据模型召回率（96.23%）</font>\n",
    "## <font color='red'>召回率和精度如一个天平，一个高，另一个就低，只能找平衡，精准度提高，召回率下降是正常的</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
